<template>
	<view class="">
		<view v-for="(item,index) in params.list" :key="index" class="card_activity">
			<ActivityCard :item="item"></ActivityCard>
		</view>
		<view v-if="params.list.length===0" class="empty_container">
			<u-empty text="当前暂无活动" mode="data" width="100%" iconSize="60" textSize="32"></u-empty>
		</view>
	</view>

</template>

<script>
	import {
		getActivity
	} from '@/api/forum.js'
	export default {
		props: ['refresh'],
		watch: {
			'refresh': {
				handler(val) {
					if (val) {
						this.pageParams.pageNum = 1
						this.getList(this.pageParams, false)
					}
				}
			}
		},
		mounted() {
			this.getList(this.pageParams)
			// 触底加载
			uni.$on('onBottom', () => {
				if (this.params.total !== this.params.list.length) {
					this.pageParams.pageNum += 1
					this.getList(this.pageParams)
				}
			})
			// 重新获取数据
			uni.$on('reloadlist', () => {
				this.pageParams.pageNum = 1
				this.getList(this.pageParams, false)
			})
		},
		data() {
			return {
				params: {
					list: [],
					total: 0,
				},
				pageParams: {
					pageNum: 1,
					pageSize: 5
				},

			}
		},
		methods: {
			// 获取帖子数据
			getList(data, flag = true) {
				if (flag) {
					getActivity(data).then(res => {
						this.params.total = res.data.total
						this.params.list = this.params.list.concat(res.data.list)
					})
				} else {
					getActivity(data).then(res => {
						this.params.total = res.data.total
						this.params.list = res.data.list
					})
				}

			},

		}
	}
</script>

<style scoped lang="scss">
	.card_activity {
		margin: 20rpx 0;

		.empty_container {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 60vh;

			.u-empty {
				height: 60vh;
			}
		}

	}
</style>